package com.cms.customplugin

import com.android.build.gradle.AppExtension
import com.android.build.gradle.internal.dsl.SigningConfig
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project


class CustomPlugin implements Plugin<Project> {

    @Override
    void apply(Project project) {
        //创建project下的扩展
        ReinforceBean reinforce = project.extensions.create("reinforce",ReinforceBean.class)
        project.afterEvaluate {

            AppExtension android = project.extensions.android
            android.applicationVariants.configureEach {variant->

                def config = variant.signingConfig
                variant.outputs.configureEach { out->
                    def file = out.outputFile
                    println "file:${out.name} ,outpuFile:${out.outputFile.absolutePath}"

                    ReinforceTask reinforceTask = project.tasks.create("reinforce${variant.name.capitalize()}",ReinforceTask)

                    reinforceTask.apk = file
                    reinforceTask.reinforceBean = reinforce
                    reinforceTask.signingConfig = config
                }
            }

        }
    }
}